* Create Figures 6 (left panel), 7 (left panel), A.4 (left panel), and A.5 (left panel)
* Save data for Figure 9
* Source data "microdata_XM" is generated by Replicate_2.m in MATLAB

import delimited using "QuantitativeModel/temp/microdata_XM", clear

ren v1 omega
ren v2 omega1
ren v3 sD
ren v4 sD1
ren v5 sX
ren v6 sX1

gen sI = 1-sD 
gen sI1 = 1-sD1 
gen deltas = sI1-sI
gen growth = (omega1-omega)/omega * 100
gen deltalog = log(omega1)-log(omega)
gen sDgrowth = (sD1-sD)/sD*100
gen sXdelta = (sX1-sX)*100
gen deltae = (sX1-sX)

* Figures:

binscatter growth sX if sX>0, n(30) xtitle(Initial Export Share) ytitle(Market Share Growth) title(Baseline Model) graphregion(color(white)) replace
graph export "Output/F6_A.pdf", replace

binscatter growth sI if sI>0, n(80) xtitle(Initial Import Share) ytitle(Market Share Growth) title(Baseline Model) graphregion(color(white)) line(qfit) replace
graph export "Output/F7_A.pdf", replace

binscatter sDgrowth sX if sX>0, n(20) xtitle(Initial Export Share) ytitle(Domestic Share Growth) title(Baseline Model) graphregion(color(white)) savedata("QuantitativeModel/temp/F9_global") replace

binscatter deltas deltae if deltas!=0 & deltae!=0, n(80) xtitle(Change Export Share) ytitle(Change Import Share) title(Baseline Model) graphregion(color(white)) replace
graph export "Output/FA4_A.pdf", replace

binscatter deltalog sXdelta if sX>0, n(20) xtitle(Change Export Share) ytitle(Change Log Market Share) title(Baseline Model) graphregion(color(white)) replace
graph export "Output/FA5_A.pdf", replace
